//some global var
var FEED_URL = "http://www.google.com/calendar/feeds/";
google.load("gdata", "1");
google.setOnLoadCallback(initf);

function login(){
    var token = google.accounts.user.login(FEED_URL);
    log("token after login:" + token);
};


function logout(){
    google.accounts.user.logout();
    init();
};

function handleError(e){
    if (e instanceof Error) {
        // Alert with the error line number, file and message.
        alert('Error at line ' + e.lineNumber +
        ' in ' +
        e.fileName +
        '\n' +
        'Message: ' +
        e.message);
        // If available, output HTTP error code and status text
        if (e.cause) {
            var errorStatus = e.cause.status;
            var statusText = e.cause.statusText;
            alert('Root cause: HTTP error ' + errorStatus + ' with status text of: ' +
            statusText);
        }
    }
    else {
        alert(e.toString());
    }
};

function initf(){
    log("initf");
    google.gdata.client.init(handleError);
    var token = google.accounts.user.checkLogin(FEED_URL);
    myService = new google.gdata.calendar.CalendarService("TimeStamp-Services");
	log('init @ '+window.location.href);
	log('token: '+token);
    if (token) {
		window.location = "ts.html";
		return ;
    }
	else {

//		str=' <link href="js/chaodai.js" type="application/json"  rel="exhibit/data" /> <table style="margin-bottom: 5px;" align="center" width="95%">             <tr>                <td>                    <div ex:role="view" ex:viewClass="Timeline" ex:label="Terms" ex:start=".birth" ex:end=".death"  ex:bubbleWidth="320" ex:topBandPixelsPerUnit="50" ex:showSummary="false" ex:timelineHeight="200" ex:topBandUnit="decade" ex:bottomBandUnit="century" ex:selectCoordinator="president">                    </div>                </td>            </tr>        </table>		';
//		document.getElementById('timeline').innerHTML=str;		
	}
}

